package org.example.Server.mapper.user;

import org.apache.ibatis.annotations.*;
import org.example.Server.model.user.Student;
import org.example.Server.model.user.UserDTO;
import org.example.Server.model.user.UserInfo;
import org.example.Server.model.user.UserVO;

@Mapper
public interface UserMapper {

    @Select("select id,username,phone_num,img_url,lastlogin_time,user_type from user where password=#{password} and phone_num=#{phone_num}")
    UserVO getUserByPhonePwd(UserDTO user) ;

    @Update("update user set lastlogin_time=CURRENT_TIMESTAMP where phone_num=#{phone_num}")
    void addLoginlastime(UserDTO user);

    @Select("select * from user where phone_num=#{phoneNum}")
    UserDTO getUserByPhonenum(String phoneNum);

    @Insert("insert into user (username,password,user_type,phone_num)\n" +
            "values ( #{username},#{password},#{user_type},#{phone_num})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    Integer register(UserDTO data);

    Student getUserByStuNumber(String stuNumber);

    void addStu(UserDTO data);

    void updateSemStuId(UserDTO data);

    UserInfo getUserById(Integer userId);


    /**
     * 更新个人信息
     * @param user
     */
    void updateUser(UserInfo user);

    /**
     * 更新学生学号
     * @param user
     */
    void updateStu(UserInfo user);

    String getPasswordById(Integer id);
}
